package sd.czw.com.miemiegoushop.activity;

import android.os.Bundle;
import android.support.annotation.BoolRes;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.widget.NestedScrollView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import sd.czw.com.miemiegoushop.R;
import sd.czw.com.miemiegoushop.base.CzwBaseActivity;

/**
 * Created by czw
 * desc 描述：
 * on 2017/9/29.
 */
public class BottomSheetBehavior2Activity extends CzwBaseActivity {
    @Bind(R.id.btn_showandgone)
    Button btnShowandgone;
    @Bind(R.id.lv)
    ListView lv;
    View bottomSheet;

    private List<String> titles = new ArrayList<>();
//
//    Button id_btn_show_bottom = (Button) findViewById(R.id.id_btn_show_bottom);
//    id_btn_show_bottom.setOnClickListener(new View.OnClickListener() {
//        @Override
//        public void onClick(View v) {
//            if (mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
//                mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
//            } else if (mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
//                mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
//            }
//        }
//    });
//    View id_ll_bottom_sheet_behavior_container=findViewById(R.id.id_ll_bottom_sheet_behavior_container);
//
//    RecyclerView idrv = (RecyclerView) id_ll_bottom_sheet_behavior_container.findViewById(R.id.id_rv);
//    idrv.setLayoutManager(new LinearLayoutManager(this));
//    // idrv.setLayoutManager(new GridLayoutManager(this,6));
//    idrv.setAdapter(new MyRecyclerViewAdapter());
//
//    mBottomSheetBehavior = BottomSheetBehavior.from(id_ll_bottom_sheet_behavior_container);



    @Override
    public int getLayoutId() {
        return R.layout.activity_bsheet;
    }

    @Override
    public void initView() {

        CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinator);
        bottomSheet = coordinatorLayout.findViewById(R.id.ll);
        lv.setAdapter(new MyAdapter());

    }

    @Override
    public void initData() {
        for (int i = 0; i < 10; i++){
            titles.add("item"+(i+1));
        }

        final BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
        bottomSheetBehavior.setPeekHeight(0);

        btnShowandgone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
                    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                    bottomSheetBehavior.setPeekHeight(0);
                } else if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
                    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
                    bottomSheetBehavior.setPeekHeight(BottomSheetBehavior.PEEK_HEIGHT_AUTO);
                }
            }
        });


    }

    class MyAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return titles.size();
        }

        @Override
        public Object getItem(int i) {
            return titles.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            MyViewHolder myViewHolder;
            if (view == null){
                view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.lv_item,null);
                myViewHolder = new MyViewHolder();
                myViewHolder.textView = (TextView) view.findViewById(R.id.tv_item);
                view.setTag(myViewHolder);
            }else {
                myViewHolder = (MyViewHolder) view.getTag();
            }

            myViewHolder.textView.setText(titles.get(i));
            return view;
        }

        class MyViewHolder{
            TextView textView;
        }
    }

}
